package com.pktechan.api.service.impl;

import com.pktechan.api.base.BaseMapper;
import com.pktechan.api.base.BaseServiceImpl;
import com.pktechan.api.dao.MiniSubscribeMessageRecordMapper;
import com.pktechan.api.entity.MiniSubscribeMessageRecord;
import com.pktechan.api.service.MiniSubscribeMessageRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @program: cloudfloating
 * @description: 消息订阅记录
 * @author: qx.zhang
 * @create: 2021-06-23 11:30
 **/
@Service("miniSubscribeMessageRecordService")
@Transactional
public class MiniSubscribeMessageRecordServiceImpl extends BaseServiceImpl<MiniSubscribeMessageRecord> implements MiniSubscribeMessageRecordService {

    @Autowired
    private MiniSubscribeMessageRecordMapper miniSubscribeMessageRecordMapper;

    /**
     * 由业务类实现
     *
     * @return
     */
    @Override
    public BaseMapper<MiniSubscribeMessageRecord> getBaseMapper() {
        return miniSubscribeMessageRecordMapper;
    }

    /**
     * 保存或更新
     *
     * @param miniSubscribeMessageRecord
     */
    @Override
    public void saveOrUpdate(MiniSubscribeMessageRecord miniSubscribeMessageRecord) {
        MiniSubscribeMessageRecord miniSubscribeMessageRecordOld = miniSubscribeMessageRecordMapper.getByTemplateIdAndCustId(miniSubscribeMessageRecord);
        if (miniSubscribeMessageRecordOld != null) {
            miniSubscribeMessageRecord.setId(miniSubscribeMessageRecordOld.getId());
            miniSubscribeMessageRecordMapper.update(miniSubscribeMessageRecord);
        } else {
            miniSubscribeMessageRecordMapper.save(miniSubscribeMessageRecord);
        }
    }

    /**
     * 根据OPenID查询客户是否订阅消息
     *
     * @param openId
     * @return
     */
    @Override
    public List<MiniSubscribeMessageRecord> getListByOpenId(String openId) {
        return miniSubscribeMessageRecordMapper.getListByOpenId(openId);
    }
}
